﻿using System;
using System.Collections.Generic;
using System.Text;

namespace CeA.Reports.Atendimento.DataAccess.DTO {
    [Serializable]
    public class UsuarioDTO {
        private int               m_id;
        private string            m_login;
        private string            m_password;
        private string            m_contaBloqueada;
        private List<RoleDTO>     m_roles;
        private UsuarioDetalheDTO m_detalhe;

        public UsuarioDTO()                         {
            m_roles = new List<RoleDTO>();
            m_detalhe = new UsuarioDetalheDTO();
        }

        public int Id                               {
            get { return m_id; }
            set { m_id = value; }
        }

        public string Login                         {
            get { return m_login; }
            set { m_login = value; }
        }

        public string Senha                         {
            get { return m_password; }
            set { m_password = value; }
        }

        public string ContaBloqueada                {
            get { return m_contaBloqueada; }
            set { m_contaBloqueada = value; }
        }

        public List<RoleDTO> Roles                  {
            get { return m_roles; }
        }

        public UsuarioDetalheDTO Detalhe            {
            get { return m_detalhe; }
            set { m_detalhe = value; }
        }

        public void addRole(RoleDTO role)           {
            m_roles.Add(role);
        }

        public void addRole(List<RoleDTO> roleList) {
            m_roles = roleList;
        }

        public string RolesToString()               {
            string[] roles = new string[m_roles.Count];
            
            for (int i = 0; i < m_roles.Count; i++) {
                roles[i] = m_roles[i].Nome;
            }

            return string.Join("; ", roles);
        }

        public override string ToString()           {
            StringBuilder str = new StringBuilder();

            str.AppendFormat("Role@[m_id={0};", m_id);
            str.AppendFormat(" m_login={0};", m_login);
            str.AppendFormat(" m_password={0};", m_password);
            str.AppendFormat(" m_contaBloqueada={0};", m_contaBloqueada);
            str.AppendFormat("\n m_roles={0}", RolesToString());
            str.AppendFormat("\n m_detalhe={0}\n]", m_detalhe.ToString());

            return str.ToString();
        }
    }
}
